import 'package:safetymonitor/generated/json/base/json_convert_content.dart';
import 'package:safetymonitor/app/data/entities/auth/user_profile_entity.dart';

UserProfileEntity $UserProfileEntityFromJson(Map<String, dynamic> json) {
  final UserProfileEntity userProfileEntity = UserProfileEntity();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    userProfileEntity.id = id;
  }
  final int? systemFlag = jsonConvert.convert<int>(json['systemFlag']);
  if (systemFlag != null) {
    userProfileEntity.systemFlag = systemFlag;
  }
  final String? username = jsonConvert.convert<String>(json['username']);
  if (username != null) {
    userProfileEntity.username = username;
  }
  final String? nickname = jsonConvert.convert<String>(json['nickname']);
  if (nickname != null) {
    userProfileEntity.nickname = nickname;
  }
  final String? email = jsonConvert.convert<String>(json['email']);
  if (email != null) {
    userProfileEntity.email = email;
  }
  final String? mobile = jsonConvert.convert<String>(json['mobile']);
  if (mobile != null) {
    userProfileEntity.mobile = mobile;
  }
  final int? sex = jsonConvert.convert<int>(json['sex']);
  if (sex != null) {
    userProfileEntity.sex = sex;
  }
  final String? avatar = jsonConvert.convert<String>(json['avatar']);
  if (avatar != null) {
    userProfileEntity.avatar = avatar;
  }
  final String? loginIp = jsonConvert.convert<String>(json['loginIp']);
  if (loginIp != null) {
    userProfileEntity.loginIp = loginIp;
  }
  final String? loginDate = jsonConvert.convert<String>(json['loginDate']);
  if (loginDate != null) {
    userProfileEntity.loginDate = loginDate;
  }
  final String? createTime = jsonConvert.convert<String>(json['createTime']);
  if (createTime != null) {
    userProfileEntity.createTime = createTime;
  }
  final List<UserProfileRoles>? roles = (json['roles'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<UserProfileRoles>(e) as UserProfileRoles).toList();
  if (roles != null) {
    userProfileEntity.roles = roles;
  }
  final UserProfileDept? dept = jsonConvert.convert<UserProfileDept>(json['dept']);
  if (dept != null) {
    userProfileEntity.dept = dept;
  }
  final List<UserProfilePosts>? posts = (json['posts'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<UserProfilePosts>(e) as UserProfilePosts).toList();
  if (posts != null) {
    userProfileEntity.posts = posts;
  }
  final List<UserProfileSocialUsers>? socialUsers = (json['socialUsers'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<UserProfileSocialUsers>(e) as UserProfileSocialUsers).toList();
  if (socialUsers != null) {
    userProfileEntity.socialUsers = socialUsers;
  }
  return userProfileEntity;
}

Map<String, dynamic> $UserProfileEntityToJson(UserProfileEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['systemFlag'] = entity.systemFlag;
  data['username'] = entity.username;
  data['nickname'] = entity.nickname;
  data['email'] = entity.email;
  data['mobile'] = entity.mobile;
  data['sex'] = entity.sex;
  data['avatar'] = entity.avatar;
  data['loginIp'] = entity.loginIp;
  data['loginDate'] = entity.loginDate;
  data['createTime'] = entity.createTime;
  data['roles'] = entity.roles.map((v) => v.toJson()).toList();
  data['dept'] = entity.dept.toJson();
  data['posts'] = entity.posts.map((v) => v.toJson()).toList();
  data['socialUsers'] = entity.socialUsers.map((v) => v.toJson()).toList();
  return data;
}

extension UserProfileEntityExtension on UserProfileEntity {
  UserProfileEntity copyWith({
    int? id,
    int? systemFlag,
    String? username,
    String? nickname,
    String? email,
    String? mobile,
    int? sex,
    String? avatar,
    String? loginIp,
    String? loginDate,
    String? createTime,
    List<UserProfileRoles>? roles,
    UserProfileDept? dept,
    List<UserProfilePosts>? posts,
    List<UserProfileSocialUsers>? socialUsers,
  }) {
    return UserProfileEntity()
      ..id = id ?? this.id
      ..systemFlag = systemFlag ?? this.systemFlag
      ..username = username ?? this.username
      ..nickname = nickname ?? this.nickname
      ..email = email ?? this.email
      ..mobile = mobile ?? this.mobile
      ..sex = sex ?? this.sex
      ..avatar = avatar ?? this.avatar
      ..loginIp = loginIp ?? this.loginIp
      ..loginDate = loginDate ?? this.loginDate
      ..createTime = createTime ?? this.createTime
      ..roles = roles ?? this.roles
      ..dept = dept ?? this.dept
      ..posts = posts ?? this.posts
      ..socialUsers = socialUsers ?? this.socialUsers;
  }
}

UserProfileRoles $UserProfileRolesFromJson(Map<String, dynamic> json) {
  final UserProfileRoles userProfileRoles = UserProfileRoles();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    userProfileRoles.id = id;
  }
  final String? name = jsonConvert.convert<String>(json['name']);
  if (name != null) {
    userProfileRoles.name = name;
  }
  return userProfileRoles;
}

Map<String, dynamic> $UserProfileRolesToJson(UserProfileRoles entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['name'] = entity.name;
  return data;
}

extension UserProfileRolesExtension on UserProfileRoles {
  UserProfileRoles copyWith({
    int? id,
    String? name,
  }) {
    return UserProfileRoles()
      ..id = id ?? this.id
      ..name = name ?? this.name;
  }
}

UserProfileDept $UserProfileDeptFromJson(Map<String, dynamic> json) {
  final UserProfileDept userProfileDept = UserProfileDept();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    userProfileDept.id = id;
  }
  final String? name = jsonConvert.convert<String>(json['name']);
  if (name != null) {
    userProfileDept.name = name;
  }
  final int? parentId = jsonConvert.convert<int>(json['parentId']);
  if (parentId != null) {
    userProfileDept.parentId = parentId;
  }
  return userProfileDept;
}

Map<String, dynamic> $UserProfileDeptToJson(UserProfileDept entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['name'] = entity.name;
  data['parentId'] = entity.parentId;
  return data;
}

extension UserProfileDeptExtension on UserProfileDept {
  UserProfileDept copyWith({
    int? id,
    String? name,
    int? parentId,
  }) {
    return UserProfileDept()
      ..id = id ?? this.id
      ..name = name ?? this.name
      ..parentId = parentId ?? this.parentId;
  }
}

UserProfilePosts $UserProfilePostsFromJson(Map<String, dynamic> json) {
  final UserProfilePosts userProfilePosts = UserProfilePosts();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    userProfilePosts.id = id;
  }
  final String? name = jsonConvert.convert<String>(json['name']);
  if (name != null) {
    userProfilePosts.name = name;
  }
  return userProfilePosts;
}

Map<String, dynamic> $UserProfilePostsToJson(UserProfilePosts entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['name'] = entity.name;
  return data;
}

extension UserProfilePostsExtension on UserProfilePosts {
  UserProfilePosts copyWith({
    int? id,
    String? name,
  }) {
    return UserProfilePosts()
      ..id = id ?? this.id
      ..name = name ?? this.name;
  }
}

UserProfileSocialUsers $UserProfileSocialUsersFromJson(Map<String, dynamic> json) {
  final UserProfileSocialUsers userProfileSocialUsers = UserProfileSocialUsers();
  final int? type = jsonConvert.convert<int>(json['type']);
  if (type != null) {
    userProfileSocialUsers.type = type;
  }
  final String? openid = jsonConvert.convert<String>(json['openid']);
  if (openid != null) {
    userProfileSocialUsers.openid = openid;
  }
  return userProfileSocialUsers;
}

Map<String, dynamic> $UserProfileSocialUsersToJson(UserProfileSocialUsers entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['type'] = entity.type;
  data['openid'] = entity.openid;
  return data;
}

extension UserProfileSocialUsersExtension on UserProfileSocialUsers {
  UserProfileSocialUsers copyWith({
    int? type,
    String? openid,
  }) {
    return UserProfileSocialUsers()
      ..type = type ?? this.type
      ..openid = openid ?? this.openid;
  }
}